﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d50_brxxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d50_brxx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d50_brxxMgr mgr = new d50_brxxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d50_brxx(e.Parameters[d50_brxx_Filter.ParamPrefix]));
            IList<d50_brxx> list = mgr.FindAllByPage_d50_brxx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d50_brxx_Filter.ParamPrefix]);
            d50_brxx_MainStore.DataSource = list;
            d50_brxx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d50_brxxMgr mgr = new d50_brxxMgr();
            RowSelectionModel sm = d50_brxx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d50_brxx _d50_brxx = new d50_brxx();
                _d50_brxx.zyid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d50_brxx(_d50_brxx))
                {
                    log.Debug("d50_brxx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d50_brxx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d50_brxxMgr mgr = new d50_brxxMgr();
            d50_brxx _d50_brxx = new d50_brxx();
            if (Hid.Text.Length > 0)
                _d50_brxx = mgr.FindById_d50_brxx(int.Parse(Hid.Text));
            
			_d50_brxx.zybh = Txtzybh.Text.Trim();
			_d50_brxx.mzbh = Txtmzbh.Text.Trim();
			_d50_brxx.zycs = int.Parse(TxtNumzycs.Text.Trim());
			_d50_brxx.dqbm = Txtdqbm.Text.Trim();
			_d50_brxx.hbh = Txthbh.Text.Trim();
			_d50_brxx.grbm = Txtgrbm.Text.Trim();
			_d50_brxx.grade = Txtgrade.Text.Trim();
			_d50_brxx.rbh = Txtrbh.Text.Trim();
			_d50_brxx.dzbm = Txtdzbm.Text.Trim();
			_d50_brxx.zbh = Txtzbh.Text.Trim();
			_d50_brxx.cbh = Txtcbh.Text.Trim();
			_d50_brxx.zen = Txtzen.Text.Trim();
			_d50_brxx.cun = Txtcun.Text.Trim();
			_d50_brxx.gldm = Txtgldm.Text.Trim();
			_d50_brxx.jgdm = Txtjgdm.Text.Trim();
			_d50_brxx.jgmc = Txtjgmc.Text.Trim();
			_d50_brxx.usid = Txtusid.Text.Trim();
			_d50_brxx.brlxid = Txtbrlxid.Text.Trim();
			_d50_brxx.gfbh = Txtgfbh.Text.Trim();
			_d50_brxx.brxm = Txtbrxm.Text.Trim();
			_d50_brxx.xbid = Txtxbid.Text.Trim();
			_d50_brxx.hzgx = Txthzgx.Text.Trim();
			_d50_brxx.brnl = Txtbrnl.Text.Trim();
			_d50_brxx.csrq = Txtcsrq.Text.Trim();
			_d50_brxx.yebz = Txtyebz.Text.Trim();
			_d50_brxx.hyzkmc = Txthyzkmc.Text.Trim();
			_d50_brxx.hyid = Txthyid.Text.Trim();
			_d50_brxx.csddmc = Txtcsddmc.Text.Trim();
			_d50_brxx.mzmc = Txtmzmc.Text.Trim();
			_d50_brxx.gjid = Txtgjid.Text.Trim();
			_d50_brxx.sfzh = Txtsfzh.Text.Trim();
			_d50_brxx.gzdw = Txtgzdw.Text.Trim();
			_d50_brxx.dwdh = Txtdwdh.Text.Trim();
			_d50_brxx.dwyb = Txtdwyb.Text.Trim();
			_d50_brxx.hkdz = Txthkdz.Text.Trim();
			_d50_brxx.hkyb = Txthkyb.Text.Trim();
			_d50_brxx.lxrm = Txtlxrm.Text.Trim();
			_d50_brxx.gxid = Txtgxid.Text.Trim();
			_d50_brxx.lxdz = Txtlxdz.Text.Trim();
			_d50_brxx.lxdh = Txtlxdh.Text.Trim();
			_d50_brxx.ryksid = Txtryksid.Text.Trim();
			_d50_brxx.ryksmc = Txtryksmc.Text.Trim();
			_d50_brxx.rybs = Txtrybs.Text.Trim();
			_d50_brxx.rycw = Txtrycw.Text.Trim();
			_d50_brxx.rysj = Txtrysj.Text.Trim();
			_d50_brxx.rybqid = Txtrybqid.Text.Trim();
			_d50_brxx.zkbqid = Txtzkbqid.Text.Trim();
			_d50_brxx.cyksid = Txtcyksid.Text.Trim();
			_d50_brxx.cyksmc = Txtcyksmc.Text.Trim();
			_d50_brxx.cybs = Txtcybs.Text.Trim();
			_d50_brxx.cycw = Txtcycw.Text.Trim();
			_d50_brxx.cysj = Txtcysj.Text.Trim();
			_d50_brxx.zyts = int.Parse(TxtNumzyts.Text.Trim());
			_d50_brxx.mzzd = Txtmzzd.Text.Trim();
			_d50_brxx.ryzd = Txtryzd.Text.Trim();
			_d50_brxx.zdmc = Txtzdmc.Text.Trim();
			_d50_brxx.ryqzsj = Txtryqzsj.Text.Trim();
			_d50_brxx.zyzt = Txtzyzt.Text.Trim();
			_d50_brxx.yzxs = Txtyzxs.Text.Trim();
			_d50_brxx.yzzj = Txtyzzj.Text.Trim();
			_d50_brxx.qfje = Txtqfje.Text.Trim();
			_d50_brxx.fdje = Txtfdje.Text.Trim();
			_d50_brxx.bsbl = Txtbsbl.Text.Trim();
			_d50_brxx.hjje = Txthjje.Text.Trim();
			_d50_brxx.kbje = Txtkbje.Text.Trim();
			_d50_brxx.mxhj = Txtmxhj.Text.Trim();
			_d50_brxx.etys = Txtetys.Text.Trim();
			_d50_brxx.mzys = Txtmzys.Text.Trim();
			_d50_brxx.hlzt = Txthlzt.Text.Trim();
			_d50_brxx.cwbz = Txtcwbz.Text.Trim();
			_d50_brxx.qfjsbz = Txtqfjsbz.Text.Trim();
			_d50_brxx.qfjsje1 = Txtqfjsje1.Text.Trim();
			_d50_brxx.qfjsje = Txtqfjsje.Text.Trim();
			_d50_brxx.jssj = Txtjssj.Text.Trim();
			_d50_brxx.lsh = Txtlsh.Text.Trim();
			_d50_brxx.hsx = Txthsx.Text.Trim();
			_d50_brxx.chsx = Txtchsx.Text.Trim();
			_d50_brxx.xm1 = Txtxm1.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d50_brxx(_d50_brxx);
            else
                isok = mgr.Add_d50_brxx(_d50_brxx);
            if (isok)
            {
                d50_brxx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d50_brxx中执行了保存（插入或修改），并成功");
                d50_brxx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}